﻿package mortal.game.net.command.player
{
    import Framework.MQ.*;
    import Message.BroadCast.*;
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import baseEngine.modifiers.*;
    import com.gengine.core.frame.*;
    import com.gengine.debug.*;
    import com.gengine.global.*;
    import extend.language.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.sound.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.net.broadCast.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.fight.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.utils.*;
    import mortal.game.view.*;
    import mortal.game.view.pack.social.*;
    import mortal.game.view.platform.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;

    public class RoleUpdateCommand extends BroadCastCall
    {
        private var _code:int;
        private var _shareAdd:int;
        private var _shareAddTime:int;
        public static var oldLv:int;

        public function RoleUpdateCommand(param1:Object)
        {
            super(param1);
            return;
        }// end function

        override public function call(param1:MessageBlock) : void
        {
            var _loc_3:SAttributeUpdate = null;
            var _loc_2:* = param1.messageBase as SSeqAttributeUpdate;
            this._code = _loc_2.code;
            Cache.instance.role.roleEntityInfo.updateAttribute(_loc_2.updates);
            for each (_loc_3 in _loc_2.updates)
            {
                
                this.entityInfoUpdate(_loc_3);
                this.fightInfoUpdate(_loc_3);
            }
            return;
        }// end function

        private function flyLifeAdd(param1:int) : void
        {
            var _loc_2:* = new FightUpdateAttribtue();
            _loc_2.textDirection = 1;
            _loc_2.hurtType = 0;
            _loc_2.hurtNumber = -1 * param1;
            RolePlayer.instance.cutHurtImpl(_loc_2);
            return;
        }// end function

        private function flyManaAdd(param1:int) : void
        {
            return;
        }// end function

        private function entityInfoUpdate(param1:SAttributeUpdate) : void
        {
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:String = null;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:Boolean = false;
            var _loc_11:Boolean = false;
            var _loc_12:String = null;
            var _loc_13:Boolean = false;
            var _loc_14:TVip = null;
            var _loc_15:int = 0;
            var _loc_16:Object = null;
            var _loc_17:SProxyInfo = null;
            var _loc_18:String = null;
            var _loc_19:int = 0;
            var _loc_20:Array = null;
            var _loc_2:* = Cache.instance.role.roleInfo;
            var _loc_3:* = _cache.role.entityInfo;
            switch(param1.attribute.__value)
            {
                case EEntityAttribute._EAttributeLevel:
                {
                    if (_loc_2.level != param1.value)
                    {
                        oldLv = _loc_2.level;
                        ResManager.instance.loadLevelRes();
                        this.addRoleUpgradeEffect();
                        if (param1.value >= 15)
                        {
                            this.addRoleUpgradeView();
                        }
                        _loc_2.level = param1.value;
                        NetDispatcher.dispatchCmd(ServerCommand.RoleLevelUpdate, param1.value);
                        SoundManager.instance.soundPlay(SoundTypeConst.RoleUpgrade);
                    }
                    break;
                }
                case EEntityAttribute._EAttributeLife:
                {
                    _loc_4 = param1.value - _loc_2.life;
                    _loc_2.life = param1.value;
                    NetDispatcher.dispatchCmd(ServerCommand.LifeUpdate, _loc_2.life);
                    if (this._code == UpdateCode.EUpdateCodeZazen && _loc_4 > 0)
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.ZazenGetLife, _loc_4);
                        this.flyLifeAdd(_loc_4);
                    }
                    if ((this._code == UpdateCode.EUpdateCodeUseDrugBag || this._code == UpdateCode.EUpdateCodeBagUseDrug) && _loc_4 > 0)
                    {
                        this.flyLifeAdd(_loc_4);
                    }
                    break;
                }
                case EEntityAttribute._EAttributeMana:
                {
                    _loc_5 = param1.value - _loc_2.mana;
                    _loc_2.mana = param1.value;
                    NetDispatcher.dispatchCmd(ServerCommand.ManaUpdate, _loc_2.mana);
                    if (this._code == UpdateCode.EUpdateCodeZazen && _loc_5 > 0)
                    {
                        this.flyManaAdd(_loc_5);
                        NetDispatcher.dispatchCmd(ServerCommand.ZazenGetMana, _loc_5);
                    }
                    if ((this._code == UpdateCode.EUpdateCodeUseDrugBag || this._code == UpdateCode.EUpdateCodeBagUseDrug) && _loc_5 > 0)
                    {
                        this.flyManaAdd(_loc_5);
                    }
                    break;
                }
                case EEntityAttribute._EAttributeExperience:
                {
                    _loc_2.experience = Number(param1.valueStr);
                    NetDispatcher.dispatchCmd(ServerCommand.ExpUpdate, _loc_2.experience);
                    break;
                }
                case EEntityAttribute._EAttributeExperienceAdd:
                {
                    _loc_6 = Number(param1.value);
                    if (_loc_6 > 0)
                    {
                        if (this._code == UpdateCode.EUpdateCodeBossDrop || this._code == UpdateCode.EUpdateCodeBossDropGroup)
                        {
                            _loc_7 = GameUtil.getExpAdditionStr();
                            if (this._code == UpdateCode.EUpdateCodeBossDrop)
                            {
                                MsgManager.addTipText(Language.getStringByParam(20523, _loc_6, _loc_7), MsgHistoryType.GetMsg);
                            }
                            else
                            {
                                this._shareAdd = this._shareAdd + _loc_6;
                                if (FrameManager.flashFrame.getTime() - this._shareAddTime > 3000)
                                {
                                    this._shareAddTime = FrameManager.flashFrame.getTime();
                                    MsgManager.addTipText(Language.getStringByParam(20524, this._shareAdd, _loc_7), MsgHistoryType.GetMsg);
                                    this._shareAdd = 0;
                                }
                            }
                        }
                        else
                        {
                            _loc_7 = GameUtil.getExpAdditionStr(false, true);
                            MsgManager.addTipText(Language.getStringByParam(20525, _loc_6, _loc_7), MsgHistoryType.GetMsg);
                        }
                        if (this._code == UpdateCode.EUpdateCodeZazen)
                        {
                            NetDispatcher.dispatchCmd(ServerCommand.ZazenGetExp, _loc_6);
                        }
                        else if (this._code == UpdateCode.EUpdateCodeSunBath)
                        {
                            _cache.copy.sunbath.addExp(_loc_6);
                            NetDispatcher.dispatchCmd(ServerCommand.SunbathInfoViewUpdate, null);
                        }
                        else if (this._code == UpdateCode.EUpdateCodeBossDrop)
                        {
                            NetDispatcher.dispatchCmd(ServerCommand.HangUpGetExp, _loc_6);
                        }
                    }
                    break;
                }
                case EEntityAttribute._EAttributeExperienceDel:
                {
                    MsgManager.addTipText(Language.getStringByParam(20526, param1.value), MsgHistoryType.LostMsg);
                    break;
                }
                case EEntityAttribute._EAttributeStamina:
                {
                    _loc_8 = Cache.instance.role.roleInfo.stamina;
                    Cache.instance.role.roleInfo.stamina = param1.value;
                    _loc_9 = param1.value - _loc_8;
                    if (Global.isDebugModle)
                    {
                        if (_loc_9 > 0)
                        {
                            MsgManager.addTipText(Language.getStringByParam(20527, _loc_9 * 0.01), MsgHistoryType.GetMsg);
                        }
                        else if (_loc_9 < 0)
                        {
                            MsgManager.addTipText(Language.getStringByParam(20528, _loc_9 * 0.01), MsgHistoryType.LostMsg);
                        }
                    }
                    NetDispatcher.dispatchCmd(ServerCommand.RoleStaminaUpdate, _loc_9);
                    break;
                }
                case EEntityAttribute._EAttributeFighting:
                {
                    _loc_10 = Boolean(param1.value);
                    _loc_11 = int(param1.valueStr) == EFightingType._EFightingTypePVP;
                    _loc_12 = _loc_11 ? ("PVP") : ("PVE");
                    if (_loc_11)
                    {
                        if (_loc_10)
                        {
                            MsgManager.showFightTipsImpl(Language.getStringByParam(20529, _loc_12), MsgRollTipsType.msgRollTips6);
                        }
                        else
                        {
                            MsgManager.showFightTipsImpl(Language.getStringByParam(20530, _loc_12), MsgRollTipsType.msgRollTips5);
                        }
                    }
                    break;
                }
                case EEntityAttribute._EAttributeStatus:
                {
                    _loc_13 = param1.value == EMoveStatus._EMoveStatusZazen;
                    break;
                }
                case EEntityAttribute._EAttributeFightMode:
                {
                    Cache.instance.role.playerInfo.mode = param1.value;
                    NetDispatcher.dispatchCmd(ServerCommand.FightSetModeSuccess, param1.value);
                    break;
                }
                case EEntityAttribute._EAttributeStatus:
                {
                    Log.debug("更新主角状态：", param1.value);
                    break;
                }
                case EEntityAttribute._EAttributeAnger:
                {
                    if (Cache.instance.role.roleInfo.anger == param1.value == ConstConfig.instance.getValueByName("XPSkillMaxAnger"))
                    {
                        return;
                    }
                    Cache.instance.role.roleInfo.anger = param1.value;
                    NetDispatcher.dispatchCmd(ServerCommand.AngerUpdate, param1.value);
                    break;
                }
                case EEntityAttribute._EAttributeRechargeTotalValue:
                {
                    Cache.instance.vip.reChargeMoney = param1.value;
                    NetDispatcher.dispatchCmd(ServerCommand.ReChargeMoney, param1.value);
                    break;
                }
                case EEntityAttribute._EAttributeVipLevel:
                {
                    if (!isNaN(Cache.instance.vip.level) && param1.value > 0)
                    {
                        if (Cache.instance.vip.level <= 0 && param1.value > 0)
                        {
                            VipBecomePanel.instance.show();
                        }
                        _loc_14 = VipConfig.instance.getVipConfigByType(EVipRecordType._EVipRecordTypeBag);
                        _loc_15 = Cache.instance.vip.level > 0 ? (_loc_14["vip" + Cache.instance.vip.level]) : (0);
                        if (_loc_15 < _loc_14["vip" + param1.value])
                        {
                            Cache.instance.pack.backPackCache.capacity = Cache.instance.pack.backPackCache.capacity + (_loc_14["vip" + param1.value] - _loc_15);
                            NetDispatcher.dispatchCmd(ServerCommand.BackpackUpdateByVip, null);
                        }
                        _loc_14 = VipConfig.instance.getVipConfigByType(EVipRecordType._EVipRecordTypeWarehouse);
                        _loc_15 = Cache.instance.vip.level > 0 ? (_loc_14["vip" + Cache.instance.vip.level]) : (0);
                        if (_loc_15 < _loc_14["vip" + param1.value])
                        {
                            Cache.instance.pack.warehouseCache.capacity = Cache.instance.pack.warehouseCache.capacity + (_loc_14["vip" + param1.value] - _loc_15);
                            NetDispatcher.dispatchCmd(ServerCommand.WarehouseUpdateByVip, null);
                        }
                    }
                    Cache.instance.vip.level = param1.value;
                    NetDispatcher.dispatchCmd(ServerCommand.VipLevelUp, param1.value);
                    break;
                }
                case EEntityAttribute._EAttributeSuitGroupSkill:
                {
                    Cache.instance.role.targetSuitDefense = param1.value;
                    Cache.instance.role.targetSuitAttack = int(param1.valueStr);
                    NetDispatcher.dispatchCmd(ServerCommand.TargetSuitGroupUpdate, null);
                    break;
                }
                case EEntityAttribute._EAttributeName:
                {
                    if (ReNameCardUseWin.isViewShow)
                    {
                        ReNameCardUseWin.instance.hide();
                    }
                    break;
                }
                case EEntityAttribute._EAttributeTxVip:
                {
                    if (PlatformConst.isQQ())
                    {
                        Cache.instance.platform.qqPlatJs = param1.valueStr;
                        Cache.instance.platform.pastValue = param1.value;
                        if (param1.value > 0)
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.PlatformQQBlueGetPastValue));
                        }
                        _loc_16 = JSON.parse(param1.valueStr);
                        _loc_17 = new SProxyInfo();
                        _loc_19 = ParamsConst.instance.enterType;
                        if (_loc_16)
                        {
                            if (_loc_16["tx_" + _loc_19])
                            {
                                _loc_18 = _loc_16["tx_" + _loc_19];
                            }
                            if (_loc_18)
                            {
                                _loc_20 = _loc_18.split("#");
                                _loc_17.proxyLv = int(_loc_20[0]);
                                _loc_17.proxyExtend = int(_loc_20[1]);
                                _loc_17.proxyExtend2 = int(_loc_20[2]);
                            }
                        }
                        NetDispatcher.dispatchCmd(ServerCommand.PlatformVipInfoUpdate, _loc_17);
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function fightInfoUpdate(param1:SAttributeUpdate) : void
        {
            var _loc_2:* = Cache.instance.role.fightAttribute;
            switch(param1.attribute.__value)
            {
                case EEntityAttribute._EAttributeMaxLife:
                {
                    _loc_2.maxLife = param1.value;
                    break;
                }
                case EEntityAttribute._EAttributeMaxMana:
                {
                    _loc_2.maxMana = param1.value;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function addRoleUpgradeEffect() : void
        {
            var _loc_1:* = EffectPlayerPool.instance.getEffectPlayer(GlobalStaticResUrl.UpGradeLevel, RolePlayer.instance, null, false);
            _loc_1.play(PlayMode.ANIMATION_STOP_MODE);
            return;
        }// end function

        private function addRoleUpgradeView() : void
        {
            RoleUpgradeView.instance.show();
            return;
        }// end function

    }
}
